package morenoapp.components.workplace;

import java.awt.BorderLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

/**
 * Wizard like interface.
 * @author dmitry.mamonov
 */
public class WizardWorkplace extends JSplitPane implements WorkplaceNavigator{
    JPanel navigator;
    //CardLayout cardLayout;
    //JPanel cards;
    JPanel content;
    final Workplace workplace;
    WizardWorkplace(Workplace _workplace) {
        super(JSplitPane.HORIZONTAL_SPLIT);
        setDividerLocation(260);
        this.workplace = _workplace;
        this.navigator = new WizardPanel(this);
        setLeftComponent(navigator);
        //this.cardLayout = new CardLayout();
        //this.cards = new JPanel(cardLayout);
        this.content = new JPanel(new BorderLayout());
        setRightComponent(content);
    }

    void init(Workplace _workplace) {
        activateView(getCurrentView());
    }

    void cleanup() {
        //cards.removeAll();
        //setRightComponent(new JPanel());
        content.removeAll();
    }

    @Override
    public void activateView(WorkplaceView view) {
        workplace.setCurrentView(view);
        content.removeAll();
        JComponent nestedComponent = getCurrentViewComponent();
        nestedComponent.setVisible(true); //enshure that component will be visible
        content.add(nestedComponent, BorderLayout.CENTER);
        content.revalidate();
        content.repaint();
        //setRightComponent(getCurrentViewComponent());
        //cardLayout.show(cards, view.name());
    }

    @Override
    public boolean activateNextView() {
        return workplace.activateNextView();
    }

    @Override
    public boolean activatePrevView() {
        return workplace.activatePrevView();
    }

    @Override
    public WorkplaceView getCurrentView() {
        return workplace.getCurrentView();
    }

    @Override
    public JComponent getCurrentViewComponent() {
        return workplace.getCurrentViewComponent();
    }

    @Override
    public void addNavigatorListener(WorkspaceNavigatorListener lst) {
        workplace.addNavigatorListener(lst);
    }

    @Override
    public void removeNavigatoListener(WorkspaceNavigatorListener lst) {
        workplace.removeNavigatoListener(lst);
    }
}
